﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="role-list.aspx.cs" Inherits="VQWEB.administrator.membership.role_list" %>
<asp:Content ID="Content2" ContentPlaceHolderID="Content_backend" runat="server">
    <form class="form-horizontal" action="" method="post">
    <div class="form-group">
        <label for="keyword" class="col-md-1 control-label">
            Keyword:</label>
        <div class="col-md-4">
            <input type="text" class="form-control" id="keyword" placeholder="Keyword" />
        </div>
        <div class="col-md-2">
            <button type="submit" class="btn btn-primary">
                Search
            </button>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
                <tr class="active">
                    <th>
                        #
                    </th>
                    <th>
                        <input type="checkbox" name="chkAll" value=" " />
                    </th>
                    <th>
                        Roles Name
                    </th>
                    <th>
                        User Count
                    </th>
                    <th>
                        Modules
                    </th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    </form>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("add");
        var url_ashx = "/admin/membership/handler";

        $("#btnAdd").live("click", function () {
            window.location = "/admin/membership/role/add";
        });

        $("#btnEdit").live("click", function () {
            var sId = $("input[name='chkItem']:checked").first().attr("value");
            if (sId != undefined)
                window.location = "/admin/membership/role/edit/" + sId;
        });

        $("#btnDelete").live("click", function () {
            var array = new Array();
            $('input[name="chkItem"]:checked').each(function (i) {
                array[i] = this.value;
            });
            if (array.length > 0) {
                if (confirm("Ban chac chan xoa vai tro ?")) {
                    $.post(url_ashx, { delete_roles: JSON.stringify(array) }, function (data) {
                        $("tbody").empty();
                        var plusData = $.parseJSON(data);
                        ShowRolesHtml(plusData);

                    });
                }
            }
        });

        $("#btnRefresh").live("click", function () {

        });

        $(document).ready(function () {
            $.get(url_ashx, { view_role: "view_role" }, function (data) {
                var plusData = $.parseJSON(data);
                ShowRolesHtml(plusData);
            });

        });

        function ShowRolesHtml(table) {
            var html = "";
            $.each(table, function (index, obj) {
                var role_id = obj.role_id;
                var role_name = obj.role_name;
                var role_user = obj.role_user;
                var role_module = obj.role_module;
                html += "<tr>";
                html += "<td>";
                html += index + 1;
                html += "</td>";
                html += "<td>";
                html += "<input type=\"checkbox\" name=\"chkItem\" value=" + role_id + " />";
                html += "</td>";
                html += "<td>";
                html += role_name;
                html += "</td>";
                html += "<td>";
                html += role_user;
                html += "</td>";
                html += "<td>";
                $.each(role_module, function (j, v) {
                    html += "[" + (j + 1) + "]" + v.module + "&nbsp;";
                });
                html += "</td>";
                html += "</tr>";
            });
            $("tbody").append(html);
        }
    </script>
</asp:Content>